package com.xinqing.test.algorithm.k8s.misc;

import com.alibaba.fastjson.JSON;
import com.feidee.fdcommon.authorization.AuthorizationVerify;
import com.feidee.fdcommon.authorization.model.AuthInfoModel;
import com.feidee.fdcommon.configuration.CustomConfiguration;
import com.feidee.fdcommon.model.StringResponse;
import com.feidee.fdcommon.util.HttpUtil;
import com.xinqing.test.modle.algorithm.ConvertModelDTO;
import org.apache.http.Consts;
import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.util.ArrayList;

/**
 * @Author:CHQ
 * @Date:2020/12/24 15:30
 * @Description
 */
public class SparkConvertMleap {
    public static void main(String args[]) throws Exception {
        //创建JSON格式实体对象
        ArrayList<String> sources = new ArrayList<>();
        // list.add("/user/data_team/temp/zhijie/tfmodel/ssj_wdl_emb_v1/time_sparse_202009271825");
        //list.add("/user/data_team/tmp/spark/ssj_wdl_syyyw_v5_spark_v2_202104131347");
        sources.add("/user/data_team/tmp/spark/ssj_wdl_syyyw_staytime");
        ConvertModelDTO k8sConvertMleapParam = new ConvertModelDTO
                (sources, "/user/data_team/tmp/mleap/ssj_wdl_staytime_mleap_20210430.zip");
        String data = JSON.toJSONString(k8sConvertMleapParam);

        //请求url
        String url = "http://sml.suishoudata.com/web/ui/models/convert/spark-to-mleap";

        //超时设置
        RequestConfig requestConfig = RequestConfig.custom()
                .setConnectTimeout(50000).setConnectionRequestTimeout(10000)
                .setSocketTimeout(50000).build();

        //数据准备
        HttpPost httpPost = new HttpPost(url);
        httpPost.setConfig(requestConfig);
        httpPost.addHeader("Content-Type", "application/json");
        httpPost.setEntity(new StringEntity(data));

        //执行post请求
        CloseableHttpClient httpClient = HttpClients.createDefault();
        CloseableHttpResponse response = httpClient.execute(httpPost);

        //输出请求结果
        HttpEntity entity = response.getEntity();
        String responseContent = EntityUtils.toString(entity, "UTF-8");
        System.out.println(responseContent);

        //资源关闭
        response.close();
        httpClient.close();
    }
}

